package com.sendables;

import java.awt.Color;

import com.exception.IllegalPackageException;

public abstract class Shape extends Paintable {
	public static final byte	PERMANENT	= 0;
	public static final byte	TEMPORARY	= 1;

	public static final byte	FILLED		= 0;
	public static final byte	HOLLOW		= 1;

	protected int				height;
	protected int				width;
	protected byte				temporary, filled;

	public Shape(int clientId, Color c, DoodlePoint start, int height, int width, byte filled, byte temporary)
	{
		super(clientId, c, start);
		this.height = height;
		this.width = width;
		this.filled = filled;
		this.temporary = temporary;
	}

	public Shape()
	{
		super();
	}

	public String toString()
	{
		return super.toString() + " Height: " + height + " Width: " + width + " Filled: " + isFilled() + " Temporary: "
				+ isTemporary();
	}

	@Override
	public void writeByteRepresentation(byte[] b, int[] offset)
	{
		super.writeByteRepresentation(b, offset);
		new Number(height).writeByteRepresentation(b, offset);
		new Number(width).writeByteRepresentation(b, offset);
		b[offset[0]++] = filled;
		b[offset[0]++] = temporary;
	}

	protected void parseSuper(byte[] b, int[] offset) throws IllegalPackageException
	{
		super.parseSuper(b, offset);
		height = Number.parse(b, offset).getContent();
		width = Number.parse(b, offset).getContent();
		filled = b[offset[0]++];
		temporary = b[offset[0]++];
		if (height < 0 || width < 0 || (filled != FILLED && filled != HOLLOW)
				|| (temporary != TEMPORARY && temporary != PERMANENT))
		{
			throw new IllegalPackageException("Not correctly parsed parameters.\n" + toString());
		}
	}

	public boolean isTemporary()
	{
		return temporary == TEMPORARY;
	}

	public boolean isFilled()
	{
		return filled == FILLED;
	}

	public int getAlloc()
	{
		return super.getAlloc() + alloc(height) + alloc(width) + alloc(temporary) + alloc(filled);
	}

}